package com.wwy.arithmetic.suanfa;

import com.wwy.arithmetic.suanfa.entry.ListNode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ShanChuLianBiao {

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(2);
        ListNode listNode4 = new ListNode(2);
        ListNode listNode5 = new ListNode(3);
        listNode4.setNext(listNode5);
        listNode3.setNext(listNode4);
        listNode2.setNext(listNode3);
        listNode1.setNext(listNode2);
        listNode.setNext(listNode1);
        ListNode listNode6 = deleteDuplicates(listNode);
        System.out.println("listNode6 = " + listNode6.toString());
    }

    //第一种方法
    public static ListNode deleteDuplicates(ListNode head) {
        //判断是否是空节点
        if (head == null) {
            return head;
        }
        ListNode target = head;
        while (target.getNext() != null) {
            //如果当前节点等于下一个节点信息 则将下一个节点替换为下下个节点
            if (target.getVal() == target.getNext().getVal()) {
                target.setNext(target.getNext().getNext());
            } else {
                target = target.getNext();
            }
        }
        return head;
    }




}
